<?php
namespace Modules\Activity\Entities\Jika;;

use Modules\Core\Entities\BaseEntity as Model;
use ThrowException;


// 一番赏活动 副表
class SwapRecord extends Model
{
    
    protected $table = 'jika_swap_records';

   	protected $guarded = [];
    static public $resourcename = '兑换记录';

    public function activity()
    {
        return $this->belongsTo('\Modules\Activity\Entities\Jika\Activity', 'activity_id');
    }

    public function task()
    {
        return $this->belongsTo('\Modules\Activity\Entities\Jika\Task', 'task_id');
    }

    public function sku()
    {
        return $this->belongsTo('\Modules\Activity\Entities\Jika\Sku', 'sku_id');
    }

    public function user()
    {
        return $this->belongsTo('\Modules\User\Entities\User', 'user_id');
    }

    static public function createWith($user, $sku)
    {
        $info = [
            'user_id' => $user->id,
            'sku_id' => $sku->id,
            'task_id' => $sku->task_id,
            'activity_id' => $sku->activity_id
        ];

        return self::create($info);
    }
}
